<script>
	import config from '@/app.config.js';
	const db = uniCloud.database();
	export default {
		methods: {

		},
		// 监听 - 页面404
		onPageNotFound: function(e) {
			uni.redirectTo({
				url: config.error.url
			})
		},
		async onLaunch(options) {
			console.log("options=", options);

			//=====特别重要：以下3个参数，每个小程序不一样，请务必修改=====
			let appid = "wx15c580155e3ec00e";
			let appname = "菠萝蜜短剧";
			let pid = "001"; //支付配置pid,部署前请务必确保不和本公司的其他小程序pid重复。建议值为001,002,003...等
			//=====修改结束=====

			vk.vuex.set('$app.appid', appid); //小程序appid
			vk.vuex.set('$app.appname', appname); //小程序名称
			vk.vuex.set('$app.pid', pid); //支付参数配置
			//设置邀请码保存到本地数据中
			// if (options.query.c) {
			// 	options.query.tg_pt = "aiqiyi";
			// 	options.query.clickid = options.query.c;
			// }

			// if (options.query.clue_token) {
			// 	// options.query.tg_pt = "douyin";
			// 	options.query.clickid = options.query.clue_token;
			// }

			// vk.vuex.set('$app.scene', options.scene || 0); //进入小程序场景值https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
			// uni.setStorageSync('middleman_id', options.query.middleman_id || 0)
			// uni.setStorageSync('invite_code', options.query.invite_code || 0)
			// uni.setStorageSync('tfid', options.query.tfid || 0)

			// uni.setStorageSync('clue_token', options.query.clue_token || 0) //形如：1757722816353293,1759691587760141
			// uni.setStorageSync('req_id', options.query.req_id || 0) //202303071521027CF959DD690C4C7F63D5
			// uni.setStorageSync('advertiser_id', options.query.advertiser_id || 0)
			// uni.setStorageSync('promotion_id', options.query.promotion_id || 0)
			// uni.setStorageSync('clickid', options.query.clickid || 0)
			// uni.setStorageSync('tg_pt', options.query.tg_pt || "")
			//保存当前设备环境，安卓还是iOS
			uni.getSystemInfo({
				success: (res) => {
					vk.vuex.set('$app.osName', res.osName)
				}
			});

			const app = await db.collection('a_appid').where({
				appid: appid
			}).get();
			let appinfo = app.result.data[0];
			//定义订阅消息列表
			let msglist = [appinfo.xspsx, appinfo.jjgx, appinfo.flhd];
			vk.vuex.set('$app.msglist', msglist) //订阅消息列表
			vk.vuex.set('$app.appinfo', appinfo) //把appinfo存到本地缓存
			vk.vuex.set('$app.appinfo.appsecret', "0") //安全起见，把appsecret改为0

		},
		onShow: function(options) {
			if (options.query.c) {
				options.query.tg_pt = "aiqiyi";
				options.query.clickid = options.query.c;
			}

			if (options.query.clue_token) {
				options.query.tg_pt = "douyin";
				options.query.clickid = options.query.clue_token;
			}

			vk.vuex.set('$app.scene', options.scene ||
				0); //进入小程序场景值https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
			uni.setStorageSync('middleman_id', options.query.middleman_id || 0)
			uni.setStorageSync('invite_code', options.query.invite_code || 0)
			uni.setStorageSync('tfid', options.query.tfid || 0)

			uni.setStorageSync('clue_token', options.query.clue_token || 0) //形如：1757722816353293,1759691587760141
			uni.setStorageSync('req_id', options.query.req_id || 0) //202303071521027CF959DD690C4C7F63D5
			uni.setStorageSync('advertiser_id', options.query.advertiser_id || 0)
			uni.setStorageSync('promotion_id', options.query.promotion_id || 0)
			uni.setStorageSync('clickid', options.query.clickid || 0)
			uni.setStorageSync('tg_pt', options.query.tg_pt || "")
			//设置常用起始时间
			vk.vuex.set('$app.time', vk.pubfn.getCommonTime(new Date()))
			if (config.debug) console.log('App Show')
		},
		onHide: function() {
			if (config.debug) console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	// @import "./uni_modules/vk-uview-ui/index.scss";
	@import "./common/css/app.scss";
	@import "./uni_modules/uview-ui/index.scss";
</style>